<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Contracts\Validation\Validator;

class StoreNotifyRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    protected function failedValidation(Validator $validator)
    {
        throw new HttpResponseException(response()->json([
            'code' => 403, // 你想要的状态码
            'msg' => $validator->errors()->all()[0]
        ], 200)); // 同样设置响应码为422
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, mixed>
     */
    public function rules()
    {
        return [
            'days' => 'required',
            'type_id' => 'required',
            'user_id' => 'required',
            'module' => 'required',
        ];
    }

    /**
     * 获取已定义验证规则的错误消息。
     *
     * @return array
     */
    public function messages()
    {
        return [
            'days.required' => '请输入逾期天数',
            'type_id.required' => '请选择类型',
            'user_id.required' => '请选择用户',
            'module.required' => '参数错误',
        ];
    }
}
